package br.com.sig.financeiro.frete.presentation.action;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.sig.cadastro.endereco.business.model.entity.Endereco;
import br.com.sig.cadastro.recursoshumanos.business.model.entity.Funcionario;
import br.com.sig.financeiro.frete.business.model.bo.FreteBO;
import br.com.sig.financeiro.frete.business.model.entity.Frete;
import br.com.sig.financeiro.locacao.business.model.entity.Locacao;
import br.com.sig.presentation.action.BaseAction;

@Named
@ViewScoped
public class FreteAction extends BaseAction<Frete> {

	private static final long serialVersionUID = 8645931650182363675L;
	
	//Modal Parameter
	private Funcionario responsavel;
	private Locacao locacao;

	@Inject
	private FreteBO freteBO;
	
	@PostConstruct
	public void init() {
		setService(freteBO);
	}
	
	@Override
	protected Frete createInstance() {
		Frete frete = super.createInstance();
		frete.setLocacao(new Locacao());
		frete.getLocacao().setEndereco(new Endereco());
		return frete;
	}
	
	public Funcionario getResponsavel() {
		return responsavel;
	}

	public void setResponsavel(Funcionario responsavel) {
		this.responsavel = responsavel;
	}

	public Locacao getLocacao() {
		return locacao;
	}

	public void setLocacao(Locacao locacao) {
		this.locacao = locacao;
	}

	public void getResponsavelCliente() {
		if (getInstance().getLocacao() != null) {
			getInstance().setResponsavel(getInstance().getLocacao().getCliente().getResponsavel());
		}
	}
	
	@Override
	public void startModal() {
		super.startModal();
		if (getResponsavel() != null) {
			getInstance().setResponsavel(getResponsavel());
		}
		
		if (getLocacao() != null) {
			getInstance().setLocacao(getLocacao());
		}
	}
}